import random


def locate_element ( xpath ):
    return random . choice ([ True , False , False ])
xpaths =["//inpuet[@id ='username']","//button[text()='提交']"]
for xpath in xpaths :
    retry =0
    while retry <3:
        if locate_element(xpath):
            print (f"元素（ xpath ）定位成功")
            break
        else:
            print (f"第（ retry +1）次重试．..")
            retry +=1
    else:
        print (f"元素{xpath} 水久定位失败")